package metalink.admin;

import java.util.ArrayList;
import java.util.Vector;

import model.admin.GetBatchListMo;
import model.admin.GetCourseListMo;

import vo.DepartmentDetailsVo;
import vo.StudentDetailsVo;
import vo.mixed.CourseListVo;
import vo.mixed.DegreeListVo;
import vo.mixed.DepartmentListVo;
import vo.mixed.StudentListVo;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class GetDegreeList extends ActionSupport {

	@SuppressWarnings("unused")
	int degree_id;
	int batch_id;
	int department_id;
	String value="";
	ArrayList<DegreeListVo> degree_list;
	ArrayList<StudentListVo> degree_student_list;
	ArrayList<CourseListVo> degree_course_list;
	ArrayList<DepartmentListVo> degree_department_list;
	ArrayList<CourseListVo> degree_department_course_list;
	ArrayList<DepartmentDetailsVo> department = new ArrayList<DepartmentDetailsVo>();
	
	private int result;

	//------------ Pagination --------------//
	private int page;
	private String morepages;
	private Vector noofpages=new Vector();
	private int nextpage;
	private int currentpage;
	private String hasprevpage;
	private int prevpage;
	private int items;
	//private Vector pagelist=new Vector();
	private ArrayList<DepartmentListVo> pagelist;

	public ArrayList<CourseListVo> getDegree_course_list() {
		return degree_course_list;
	}

	public ArrayList<CourseListVo> getDegree_department_course_list() {
		return degree_department_course_list;
	}

	public void setDegree_department_course_list(
			ArrayList<CourseListVo> degree_department_course_list) {
		this.degree_department_course_list = degree_department_course_list;
	}

	public int getBatch_id() {
		return batch_id;
	}

	public void setBatch_id(int batch_id) {
		this.batch_id = batch_id;
	}

	public int getDegree_id() {
		return degree_id;
	}

	public void setDegree_id(int degree_id) {
		this.degree_id = degree_id;
	}

	public void setDegree_course_list(ArrayList<CourseListVo> degree_course_list) {
		this.degree_course_list = degree_course_list;
	}

	public ArrayList<DepartmentListVo> getDegree_department_list() {
		return degree_department_list;
	}

	public void setDegree_department_list(
			ArrayList<DepartmentListVo> degree_department_list) {
		this.degree_department_list = degree_department_list;
	}

	public ArrayList<DegreeListVo> getDegree_list() {
		return degree_list;
	}

	public void setDegree_student_list(
			ArrayList<StudentListVo> degree_student_list) {
		this.degree_student_list = degree_student_list;
	}

	public ArrayList<StudentListVo> getDegree_student_list() {
		return degree_student_list;
	}

	public void setDegree_list(ArrayList<DegreeListVo> degree_list) {
		this.degree_list = degree_list;
	}

	public String execute() {
		GetBatchListMo degree_list_object = new GetBatchListMo();
		GetCourseListMo coursemo = new GetCourseListMo();
		if(value.contentEquals("viewdep")){
			try {
				pagelist = new ArrayList<DepartmentListVo>();
				department = degree_list_object.getAddDepartmenttoDegreeList(degree_id);
				degree_department_list = degree_list_object.getDepartmentList(0, degree_id, 0);
//---------- Pagination ------------------//
				result = degree_department_list.size();
				int p=getPage();
		        if(p==0)
		        {
		            setHasprevpage("false");
		        }
		        else
		        {
		            setHasprevpage("true");
		            setPrevpage(p-1);
		        }

		        setCurrentpage(p);

		        int count;
		        count=0;

		        int size=degree_department_list.size();
		        setItems(size);
		        int pagesinlist=size/15;
		        while(count<=pagesinlist)
		        {
		            noofpages.add(count);
		            count++;
		        }
		        count=0;
		        while(count<15)
		        {

		            if(size>=(p*15)+count+1)
		            {
		                System.out.println(p);
		                pagelist.add(degree_department_list.get((p*15)+count));
		                System.out.println((p*15)+count);
		                System.out.println("size"+pagelist.size());
		                count++;
		                setMorepages("true");
		                setNextpage(p+1);

		            }
		            else
		            {
		                setMorepages("false");
		                break;
		            }
		        }
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else if(value.contentEquals("updatedepdep")){
			try {
				pagelist = new ArrayList<DepartmentListVo>();
				coursemo.updateDegreeDep(degree_id, department_id,value);
				department = degree_list_object.getAddDepartmenttoDegreeList(degree_id);
				degree_department_list = degree_list_object.getDepartmentList(0, degree_id, 0);
//---------- Pagination ------------------//
				result = degree_department_list.size();
				int p=getPage();
		        if(p==0)
		        {
		            setHasprevpage("false");
		        }
		        else
		        {
		            setHasprevpage("true");
		            setPrevpage(p-1);
		        }

		        setCurrentpage(p);

		        int count;
		        count=0;

		        int size=degree_department_list.size();
		        setItems(size);
		        int pagesinlist=size/15;
		        while(count<=pagesinlist)
		        {
		            noofpages.add(count);
		            count++;
		        }
		        count=0;
		        while(count<15)
		        {

		            if(size>=(p*15)+count+1)
		            {
		                System.out.println(p);
		                pagelist.add(degree_department_list.get((p*15)+count));
		                System.out.println((p*15)+count);
		                System.out.println("size"+pagelist.size());
		                count++;
		                setMorepages("true");
		                setNextpage(p+1);

		            }
		            else
		            {
		                setMorepages("false");
		                break;
		            }
		        }
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else if (value.contentEquals("deletedep")){
			try {
				pagelist = new ArrayList<DepartmentListVo>();
				coursemo.deleteDegreeDepartment(degree_id, department_id,value);
				department = degree_list_object.getAddDepartmenttoDegreeList(degree_id);
				degree_department_list = degree_list_object.getDepartmentList(0, degree_id, 0);
//---------- Pagination ------------------//
				result = degree_department_list.size();
				int p=getPage();
		        if(p==0)
		        {
		            setHasprevpage("false");
		        }
		        else
		        {
		            setHasprevpage("true");
		            setPrevpage(p-1);
		        }

		        setCurrentpage(p);

		        int count;
		        count=0;

		        int size=degree_department_list.size();
		        setItems(size);
		        int pagesinlist=size/15;
		        while(count<=pagesinlist)
		        {
		            noofpages.add(count);
		            count++;
		        }
		        count=0;
		        while(count<15)
		        {

		            if(size>=(p*15)+count+1)
		            {
		                System.out.println(p);
		                pagelist.add(degree_department_list.get((p*15)+count));
		                System.out.println((p*15)+count);
		                System.out.println("size"+pagelist.size());
		                count++;
		                setMorepages("true");
		                setNextpage(p+1);

		            }
		            else
		            {
		                setMorepages("false");
		                break;
		            }
		        }
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else{
		setDegree_list(degree_list_object.getBatchDegreeList(0));
		}
		return SUCCESS;
	}
	
	
	
	/*
	public String execute() {
		GetBatchListMo degree_list_object = new GetBatchListMo();
		setDegree_list(degree_list_object.getBatchDegreeList(0));
		
		pagelist = new ArrayList<DegreeListVo>();
		result = degree_list.size();
				
				//---------- Pagination ------------------//
				
				int p=getPage();
		        if(p==0)
		        {
		            setHasprevpage("false");
		        }
		        else
		        {
		            setHasprevpage("true");
		            setPrevpage(p-1);
		        }

		        setCurrentpage(p);

		        int count;
		        count=0;

		        int size=degree_list.size();
		        setItems(size);
		        int pagesinlist=size/15;
		        while(count<=pagesinlist)
		        {
		            noofpages.add(count);
		            count++;
		        }
		        count=0;
		        while(count<15)
		        {

		            if(size>=(p*15)+count+1)
		            {
		                System.out.println(p);
		                pagelist.add(degree_list.get((p*15)+count));
		                System.out.println((p*15)+count);
		                System.out.println("size"+pagelist.size());
		                count++;
		                setMorepages("true");
		                setNextpage(p+1);

		            }
		            else
		            {
		                setMorepages("false");
		                break;
		            }
		        }
		
		
		return SUCCESS;
	}
*/
	public String getDegreeStudentDetails() {
		GetBatchListMo degree_student_obj = new GetBatchListMo();
		setDegree_student_list(degree_student_obj.getDegreeStudentList(
				degree_id, 0));
		System.out.println(degree_id);
		return SUCCESS;
	}

	public String getDegreeCourseDetails() throws Exception {
		GetCourseListMo degree_course_obj = new GetCourseListMo();
		setDegree_course_list(degree_course_obj.getDegreeDepartmentCourseList(degree_id, 0));
		

		return SUCCESS;
	}
/*
	public String getDegreeDepartmentDetails() throws Exception {
		GetBatchListMo degree_department_obj = new GetBatchListMo();
		setDegree_department_list(degree_department_obj.getDepartmentList(0,
				degree_id));
		return SUCCESS;
	}
*/
	public String getDegreeDepartmentCourseDetails() throws Exception {
		GetCourseListMo degree_department_course_obj = new GetCourseListMo();
		setDegree_department_course_list(degree_department_course_obj
				.getDegreeDepartmentCourseList(degree_id, department_id));
		return SUCCESS;
	}

	public int getDepartment_id() {
		return department_id;
	}

	public void setDepartment_id(int department_id) {
		this.department_id = department_id;
	}

	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getMorepages() {
		return morepages;
	}

	public void setMorepages(String morepages) {
		this.morepages = morepages;
	}

	public Vector getNoofpages() {
		return noofpages;
	}

	public void setNoofpages(Vector noofpages) {
		this.noofpages = noofpages;
	}

	public int getNextpage() {
		return nextpage;
	}

	public void setNextpage(int nextpage) {
		this.nextpage = nextpage;
	}

	public int getCurrentpage() {
		return currentpage;
	}

	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}

	public String getHasprevpage() {
		return hasprevpage;
	}

	public void setHasprevpage(String hasprevpage) {
		this.hasprevpage = hasprevpage;
	}

	public int getPrevpage() {
		return prevpage;
	}

	public void setPrevpage(int prevpage) {
		this.prevpage = prevpage;
	}

	public int getItems() {
		return items;
	}

	public void setItems(int items) {
		this.items = items;
	}

	public ArrayList<DepartmentListVo> getPagelist() {
		return pagelist;
	}

	public void setPagelist(ArrayList<DepartmentListVo> pagelist) {
		this.pagelist = pagelist;
	}

	public ArrayList<DepartmentDetailsVo> getDepartment() {
		return department;
	}

	public void setDepartment(ArrayList<DepartmentDetailsVo> department) {
		this.department = department;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
}
